import Vue from 'vue'
import VueRouter from 'vue-router'
import { routes as movie } from './module/movie/router'
import { routes as user } from './module/user/router'
import store from './store'

Vue.use(VueRouter)

const myRouter = new VueRouter({
  routes: [
    ...movie,
    ...user,
    {
      path: '/',
      redirect: '/index'
    }
  ]
})
myRouter.beforeEach((to, from, next) => {
  console.log(store.state)
  if (!to.meta.noLogin && store.state.isLogin === '2') {
    next({
      path: `/user/login?redirect=${encodeURIComponent(to.path)}`
    })
  } else {
    next()
  }
})
export default myRouter
